package com.example.springstudy.interceptor;

import org.springframework.boot.web.servlet.server.Session;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author jiujiu
 * <p>
 * 拦截器创建（定义）
 * 实现 HandlerInterceptor
 */

public class TestIntercept implements HandlerInterceptor {


    /**重写方法，调用目标方法之前拦截 通过session来判断是非由*/
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object session = request.getSession().getAttribute("login");
        if (session != null) {
            /*表示登录*/
            return true;
        }
        return true;
    }
}
